import java.awt.*;
import java.util.*;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Doudizhu {
    private ArrayList<Card> list = new ArrayList();
    private String[] point = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};
    private String[] type = {"♠", "♥", "♣", "♦"};

    public static void main(String[] args) {
        Doudizhu doudizhu = new Doudizhu();
        doudizhu.init();
        doudizhu.xipai();
        doudizhu.fapai();
    }

    // 初始化54张扑克牌
    public void init() {
//        String card = "";
        for (int i = 0; i < point.length; i++) {
            for (int j = 0; j < type.length; j++) {
//                card = type[j] + point[i];
                list.add(new Card(type[j], point[i]));
            }
        }
        list.add(new Card("", "小王"));
        list.add(new Card("", "大王"));
        System.out.println(list);
    }

    // 洗牌
    public void xipai() {
        Collections.shuffle(list);
        System.out.println(list);
    }

    // 发牌
    public void fapai() {
        System.out.println("玩家一：" + sort(list.subList(0, 17)));
        System.out.println("玩家二：" + sort(list.subList(17, 34)));
        System.out.println("玩家三：" + sort(list.subList(34, 51)));
        System.out.println("底牌" + list.subList(51, 54));
    }

    //排序
    public List sort(List sublist) {

        sublist.sort(new Comparator<Card>() {
            @Override
            public int compare(Card c1, Card c2) {
                int index1 = -1;
                int index2 = -1;
                if (c1.getPoint().equals("小王")) {
                    index1 = 50;
                } else if (c1.getPoint().equals("大王")) {
                    index1 = 100;
                }

                if (c2.getPoint().equals("小王")) {
                    index2 = 50;
                } else if (c2.getPoint().equals("大王")) {
                    index2 = 100;
                }

                for (int i = 0; i < point.length; i++) {
                    if (c1.getPoint().equals(point[i])) {
                        index1 = i;
                    }
                    if (c2.getPoint().equals(point[i])) {
                        index2 = i;
                    }
                }
                return index1 - index2;
            }
        });
        return sublist;
    }


}